<!DOCTYPE html>
<html lang="zh-cn">
   <head>
      <meta charset="utf-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <title>{$CONF['mallTitle']}后台管理中心</title>
      <link href="__PUBLIC__/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet">
      <link href="__CSS__/AdminLTE.css" rel="stylesheet" type="text/css" />
      <link rel="stylesheet" href="__JS__/daterangepicker/daterangepicker-bs3.css">
      <link href="__CSS__/upload.css" rel="stylesheet" type="text/css" />
      <!--[if lt IE 9]>
      <script src="__PUBLIC__/js/html5shiv.min.js"></script>
      <script src="__PUBLIC__/js/respond.min.js"></script>
      <![endif]-->
      <script src="__PUBLIC__/js/jquery.min.js"></script>
      <script src="__PUBLIC__/plugins/bootstrap/js/bootstrap.min.js"></script>
      <script src="__JS__/daterangepicker.js"></script>
      <script src="__PUBLIC__/js/common.js"></script>
      <script src="__PUBLIC__/plugins/plugins/plugins.js"></script>
      <script src="__PUBLIC__/plugins/formValidator/formValidator-4.1.3.js"></script>
      <script type="text/javascript" src="__JS__/upload.js"></script>

   </head>
   <script>
   var ThinkPHP = window.Think = {
	        "ROOT"   : "__ROOT__"
	}
   var filetypes = ["gif","jpg","png","jpeg"];
   $(function () {
	   $.formValidator.initConfig({
		   theme:'Default',mode:'AutoTip',formID:"myform",debug:true,submitOnce:true,onSuccess:function(){
				   edit();
			       return false;
			},onError:function(msg){
		}});

	   $("#adPositionId").formValidator({onFocus:"请选择广告位置"}).inputValidator({min:1,onError: "请选择广告位置"});
	   $("#adName").formValidator({empty:false,onFocus:"请输入广告标题"}).inputValidator({min:1,onError: "请输入广告标题"});
	   $('#adDateRange').daterangepicker({format:'YYYY-MM-DD',separator:' 至 '});
	   <if condition="$object['adId'] !=0 ">
	   getAreaList("areaId2",{$object.areaId1},0,{$object.areaId2});
	   </if>
   });
   function getAreaList(objId,parentId,t,id){
	   var params = {};
	   params.parentId = parentId;
	   $('#'+objId).empty();
	   if(t<1){
		   $('#areaId3').empty();
		   $('#areaId3').html('<option value="">请选择</option>');
	   }
	   var html = [];
	   $.post("{:U('Admin/Areas/queryByList')}",params,function(data,textStatus){
		    html.push('<option value="">请选择</option>');
			var json = WST.toJson(data);
			if(json.status=='1' && json.list.length>0){
				var opts = null;
				for(var i=0;i<json.list.length;i++){
					opts = json.list[i];
					html.push('<option value="'+opts.areaId+'" '+((id==opts.areaId)?'selected':'')+'>'+opts.areaName+'</option>');
				}
			}
			$('#'+objId).html(html.join(''));
	   });
   }
   function edit(){
	   var params = {};
	   params.id = $('#id').val();
	   params.areaId1 = $('#areaId1').val();
	   params.areaId2 = $('#areaId2').val();
	   params.areaId3 = $('#areaId3').val();
     params.adPositionId = $('#adPositionId').val();
	   params.adSort = $('#adSort').val();
	   params.adName = $.trim($('#adName').val());
	   params.adFile = $.trim($('#adFile').val());
	   params.adURL = $.trim($('#adURL').val());
     params.adURLApp = $.trim($('#adURLApp').val());
	   var date = $('#adDateRange').val().split(' 至 ');
	   params.adStartDate = date[0];
	   params.adEndDate = date[1];
     /*
	   if(params.adFile==''){
		   Plugins.Tips({title:'信息提示',icon:'error',content:'请上传广告图片!',timeout:1000});
		   return;
	   }
     */
	   Plugins.waitTips({title:'信息提示',content:'正在提交数据，请稍后...'});
		$.post("{:U('Admin/Ads/edit')}",params,function(data,textStatus){
			var json = WST.toJson(data);
			if(json.status=='1'){
				Plugins.setWaitTipsMsg({ content:'操作成功',timeout:1000,callback:function(){
				   location.href='{:U("Admin/Ads/index")}';
				}});
			}else{
				Plugins.closeWindow();
				Plugins.Tips({title:'信息提示',icon:'error',content:'操作失败!',timeout:1000});
			}
		});
   }
   </script>
   <body class="wst-page">
   	<iframe name="upload" style="display:none"></iframe>
			<form id="uploadform_Filedata" autocomplete="off" style="position:absolute;top:108px;left:120px;z-index:10;" enctype="multipart/form-data" method="POST" target="upload" action="{:U('Home/Shops/uploadPic')}" >
				<div style="position:relative;">
				<input id="adFile" name="adFile" class="form-control wst-ipt" type="text" value="{$object.adFile}" readonly style="margin-right:4px;float:left;margin-left:8px;width:250px;"/>
				<div class="div1">
					<div class="div2">浏览</div>
					<input type="file" class="inputstyle" id="Filedata" name="Filedata" onchange="updfile('Filedata');" >
				</div>
				<div style="clear:both;"></div>
				<div >&nbsp;图片大小:1400 x 300 (px)(格式为 gif, jpg, jpeg, png)</div>
				<input type="hidden" name="dir" value="adss">
				<input type="hidden" name="width" value="1400">
				<input type="hidden" name="folder" value="Filedata">
				<input type="hidden" name="sfilename" value="Filedata">
				<input type="hidden" name="fname" value="adFile">
				<input type="hidden" id="s_Filedata" name="s_Filedata" value="">

				</div>
		</form>
       <form name="myform" method="post" id="myform" autocomplete="off">
        <input type='hidden' id='id' value='{$object.adId}'/>
        <table class="table table-hover table-striped table-bordered wst-form">
           <tr>
             <th align='right'>广告城市：</th>
             <td>
             <select id='areaId1' onchange='javascript:getAreaList("areaId2",this.value,0)'>
                <option value=''>请选择</option>
                <volist name="areaList" id="vo">
                <option value='{$vo['areaId']}' <if condition="$object['areaId1'] == $vo['areaId'] ">selected</if>>{$vo['areaName']}</option>
                </volist>
             </select>
             <select id='areaId2'>
               <option value=''>请选择</option>
             </select>
             (不选则默认整个商城)
             </td>
           </tr>
           <tr>
             <th align='right'>广告位置<font color='red'>*</font>：</th>
             <td>
             <select id='adPositionId'>
                <option value=''>请选择</option>

                <option value='-1' <if condition="$object['adPositionId'] == -1 ">selected</if>>首页主广告</option>
                <!-- <option value='-4' >首页副广告</option>

                <option value='-5' >首页商城头条</option>
                <option value='-2' ></option>
                <option value='-3' >店铺街广告</option> -->

                <option value='0' <if condition="$object['adPositionId'] == 0 ">selected</if>>微帮</option>
                <!-- <option value='1' >云购</option> -->
                <option value='2' <if condition="$object['adPositionId'] == 2 ">selected</if>>积分商城</option>
                <option value='3' <if condition="$object['adPositionId'] == 3 ">selected</if>>新店来袭</option>

             </select>
             </td>
           </tr>
           <tr>
             <th width='120' align='right'>广告标题<font color='red'>*</font>：</th>
             <td><input type='text' id='adName' class="form-control wst-ipt" value='{$object.adName}' maxLength='25'/></td>
           </tr>
           <tr style="height:70px;">
             <th align='right'>广告图片：</th>
             <td></td>
           </tr>
           <tr>
             <th align='right'>预览图：</th>
             <td height='40'>
             	<div id="preview_Filedata">
               <img id='preview' src='__ROOT__/{$object.adFile}' height='152' <if condition="$object['adFile'] =='' ">style='display:none'</if>/>
               </div>
             </td>
           </tr>
           <tr>
             <th align='right'>PC跳转网址：</th>
             <td>
             <input type='text' id='adURL' class="form-control wst-ipt" value='{$object.adURL}'/>
             </td>
           </tr>
            <tr>
             <th align='right'>APP跳转：</th>
             <td>
             <input type='text' id='adURLApp' class="form-control wst-ipt" value='{$object.adURLApp}'/>(S|1 或 G|1 S代表店铺G代表商品，|后面的1分别是店铺或商品的ID)
             </td>
           </tr>
           <tr>
             <th align='right'>广告日期<font color='red'>*</font>：</th>
             <td>
             <input type='text' id='adDateRange' class="form-control" readonly='true' style='width:300px' value='{$object.adStartDate} 至 {$object.adEndDate}'/>
             </td>
           </tr>
           <tr>
             <th align='right'>广告排序号：</th>
             <td>
             <input type='text' id='adSort' class="form-control"  value='{$object.adSort}' style='width:80px' onkeypress="return WST.isNumberKey(event)" onkeyup="javascript:WST.isChinese(this,1)" maxLength='8'/>
             </td>
           </tr>
           <tr>
             <td colspan='2' style='padding-left:250px;'>
                 <button type="submit" class="btn btn-success">保&nbsp;存</button>
                 <button type="button" class="btn btn-primary" onclick='javascript:location.href="{:U('Admin/Ads/index')}"'>返&nbsp;回</button>
             </td>
           </tr>
        </table>
       </form>
   </body>
</html>